var AppSettings = Class.create({ 
	initialize: function() { 
	
	}
});

//groupon.cn
AppSettings.CouponRequestURI = "http://www.mcdonalds.com.cn/mclub/coupon_print2.aspx";
AppSettings.CouponDirectoryURI = "http://www.mcdonalds.com.cn/mclub/";
AppSettings.RegExp = new RegExp("<\\s*\\/?\\s*img\\s*.*?>","g");
AppSettings.locale = 'zh_cn';
AppSettings.lastUpdateTime = '';

AppSettings.init = function() {

	//set locale according to settings
	var localeCookie = new Mojo.Model.Cookie("_locale");
	var localetemp = localeCookie.get();
	if (localetemp) {
		AppSettings.locale = localetemp;
	}else
	{
		AppSettings.locale = 'zh_cn';
		localeCookie.put("zh_cn"); //default to zh_cn
	}
	this.changeLocale(AppSettings.locale);
	
	this.getLastUpdateTime();
	
	
	//load saved coupon list
	this.loadCoupon();
}

AppSettings.changeLocale = function(newLocale) {
	if (newLocale != null) {
		AppSettings.locale = newLocale;
	}

	Mojo.Locale.set (this.locale);
}

AppSettings.loadCoupon = function() {

	//load coupon list for local cache
	var couponCookie = new Mojo.Model.Cookie("couponList");
	var couponListTemp = couponCookie.get();
	if (couponListTemp) {
		MCModels.couponList = couponListTemp;
	}
	return MCModels.couponList;
}

AppSettings.saveCoupon = function() {

	//save coupon list to local cache
	var couponCookie = new Mojo.Model.Cookie("couponList");
	couponCookie.put(MCModels.couponList);
}


AppSettings.getLastUpdateTime = function() {
	var lastUpdateTimeCookie = new Mojo.Model.Cookie("lastUpdateTime");
	var lastUpdateTimeTmp = lastUpdateTimeCookie.get();
	if (lastUpdateTimeTmp) {
		AppSettings.lastUpdateTime = lastUpdateTimeTmp;
	}else
	{
		AppSettings.lastUpdateTime = '1975/01/01';
	}
	
	return AppSettings.lastUpdateTime;
}

AppSettings.setLastUpdateTime = function(lastUpdateDate) {
	AppSettings.lastUpdateTime = Mojo.Format.formatDate(lastUpdateDate,{date:'short',time:"HH:mm"});
	var lastUpdateTimeCookie = new Mojo.Model.Cookie("lastUpdateTime");
	lastUpdateTimeCookie.put(AppSettings.lastUpdateTime);
}